Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor create2 #87

Closed
wants to merge 6 commits into from
Closed

Refactor create2 #87

wants to merge 6 commits into from

Conversation

QGarchery
Copy link
Contributor

@QGarchery QGarchery commented Oct 28, 2024

This PRs makes so the constructor of the PreLiquidation contract does not take any argument, and instead fetches them for the sender (which is expected to be the factory). To avoid collisions, the salt is used, by simply setting it to the hash of the parameters.

The purpose is to:

  • be able pre-compute the init code hash, which was very long. This allows notably to make it reasonable to compute the expected address of the pre-liquidation contract onchain;
  • be more efficient gas-wise in pre-liquidation deployment, because it avoids to do a "very cold" SSTORE to set isPreLiquidation. Instead it uses the computation of the expected address of the pre-liquidation contract;
  • being able to return an appropriate error message when the pre-liquidation contract was already deployed.

Todo:

  • decide if this solution is worth it at this stage in the development
  • improve gas efficiency, as it is basically unusable at the moment. See comments Not optimized yet:
    • make storage variables in the factory be transient variables
    • only one call to the candidate pre-liquidation contract in isPreLiquidation
    • only one call to the factory in the constructor of the pre-liquidation contract
  • complete natspecs

@QGarchery QGarchery self-assigned this Oct 28, 2024
@peyha
Copy link
Collaborator

peyha commented Oct 28, 2024

Interesting !
Got some concerns though

  1. This feature makes the code more complex, can you quantify how much gas this can save during pre-liquidation deployment ? Want to make sure that this is worth it
  2. Implementing transient storage requires either to update the solidity version to 0.8.28 to enable the use of the transient keyword either to use assembly to use TLOAD and TSTORE, potentially making the code harder to read
  3. If we were to implement this, would we need to re-audit the whole project ? From a security standpoint it seems like a minor update but it still means using new opcodes so it would be best to run another round of audit

@QGarchery
Copy link
Contributor Author

This feature makes the code more complex, can you quantify how much gas this can safe during pre-liquidation deployment ? Want to make sure that this is worth it

Not sure but this should be less than 20k gas, the cost of a very cold SSTORE. This may not be the most important benefit of this PR though: making it possible to have deterministic addresses onchain, and being able to have a nice error message should bring the most benefit

Agree with point 2, until we get proper support in solidity.

Also agree with point 3, this is probably too late. But this was more meant as a demonstration of what we could do in the future than an actual PR we should merge right now

@MathisGD
Copy link
Contributor

MathisGD commented Oct 29, 2024

  • do you have a gas cost comparison?
  • note that the deployment of a preliquidation is approximately 1.4M gas anyway
  • yes

@QGarchery
Copy link
Contributor Author

do you have a gas cost comparison?

No, because the PR is unusable as of now (see point 2 of the todo list). I will close it, as it was more something to have in mind for the future than anything else

@QGarchery QGarchery closed this Oct 29, 2024
@MathisGD MathisGD deleted the refactor/create2 branch October 29, 2024 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants